// Agent car0 in project DomesticRobot.mas2j



/* Initial beliefs and rules */

road_speed(0, 0.01).
road_speed(2, 0.01).
road_speed(4, 0.01).
road_speed(6, 0.01).
road_speed(8, 0.01).
road_speed(10, 0.01).
road_speed(12, 0.01).
road_speed(14, 0.01).
road_speed(16, 0.01).
road_speed(18, 0.01).
road_speed(20, 0.01).
road_speed(22, 0.01).
road_speed(24, 0.01).
road_speed(26, 0.01).
road_speed(28, 0.01).


/* Initial goals */



/*!start.*/
!go_smart.



/* Dumb way of life */

+!go_dumb: chegou <- true.

+!go_dumb: at(crossroad) <- !choose_dumb_road.

+!choose_dumb_road: .findall(X, road_best_dist(_,X), L) & .min(L, X) & road_best_dist(Y,X) <-
							goto_road(Y);
							!go_dumb.

+!go_dumb: at(road) <- move;
					  .wait(1000);
					  !go_dumb.
-!go_dumb : true <- !!go_dumb.










/* Smart way of life */

+!go_smart: chegou <- true.

+!go_smart: at(crossroad) <- !choose_smart_road.

+!choose_smart_road: .findall(X, road_speed(_,X), L) & .min(L, X) & road_speed(Y,X) & road_choice(Y) <-
							goto_road(Y);
							!go_smart.
							
+!choose_smart_road: .findall(X, road_best_dist(_,X), L) & .min(L, X) & road_best_dist(Y,X) <-
							goto_road(Y);
							!go_smart.

+!go_smart: at(road) <- move;
					  !send_info_back;
					  .wait(1000);
					  !go_smart.
-!go_smart : true <- !!go_smart.

+!send_info_back: back_car(X) & my_road(Y) & my_speed(Z) <- //.send(X, untell, road_speed(Y, _));
															.send(X, tell, road_speed(Y, Z)).

+!send_info_back: true <- true.

/* Plans */
/*
//@kqmlReceivedUnTell
+!kqml_received(Sender, untell, Content, _)
   <- .add_nested_source(Content, Sender, CA); 
      .abolish(CA).
*/
+!start : at(crossroad) <- !choose_road.


+!start : at(road) <- move;
					  .wait(1000);
					  !start.

+!choose_road : road_choice(X) <- goto_road(X);
							      !start.

-!start : true <- !!start.

+road_speed(Y,Z) : .count(road_speed(Y,_),X) & (X = 1) <- true.

+road_speed(Y,Z) : true <- .abolish(road_speed(Y,_));
						   +road_speed(Y,Z).
